﻿@using Smartstore.Core.Catalog
@using Smartstore.Core.Checkout.Cart
@using Smartstore.Web.Models.Cart

@inject CatalogSettings _catalogSettings

@model CartEntityModelBase

@{
    var parentModel = ViewData["Parent"] as CartModelBase;
    var delivery = Model.DeliveryTime;
    var showDeliveryTime = !Model.IsBundleItem && (delivery?.ShowDeliveryTime ?? false);
    var showInfos = showDeliveryTime || Model.ShowSku || Model.ShowWeight;
    var showVariants = Model.AttributeInfo.HasValue();
    var showEssentialAttributes = Model.EssentialSpecAttributesInfo.HasValue();
}

<div class="cart-item-group">
    <div sm-if="Model.Brand != null" class="cart-item-brand">
        @if (Model.Brand.Image != null)
        {
            if (_catalogSettings.LinkManufacturerLogoInLists)
            {
                <a asp-route="Manufacturer" asp-route-SeName="@Model.Brand.SeName" title="@Model.Brand.Image.Title">
                    <img sm-model="Model.Brand.Image" class="cart-item-brand-image" />
                </a>
            }
            else
            {
                <img sm-model="Model.Brand.Image" class="cart-item-brand-image" />
            }
        }
        else
        {
            <span sm-language-attributes-for="Model.Brand.Name" class="fs-sm">@Model.Brand.Name</span>
        }
    </div>

    <div class="cart-item-title">
        <a class="cart-item-link" href="@Model.ProductUrl" title="@T("Products.Details")" sm-language-attributes-for="Model.ProductName">@Model.ProductName</a>
    </div>

    @if (Model.ShowShortDesc)
    {
        <div class="cart-item-desc fs-sm" sm-language-attributes-for="Model.ShortDesc">
            @Html.Raw(Model.ShortDesc.Value.Truncate(250, "…"))
        </div>
    }
</div>

@if (parentModel.ShoppingCartType == ShoppingCartType.ShoppingCart)
{
    <zone name="cartitem_desc_after" model="Model.Id"></zone>
}

<div class="cart-item-price-group cart-item-group">
    <partial name="CartItem.Price" model="Model.Price" />

    <div sm-if="!parentModel.IsEditable" class="cart-item-qty pd-muted">
        <span>@T("Order.Product(s).Quantity"):</span> <span>@Model.EnteredQuantity @(Model.EnteredQuantity > 1 ? Model.QuantityUnitNamePlural : Model.QuantityUnitName)</span>
    </div>
</div>

<div sm-if="showInfos || showVariants || showEssentialAttributes" class="cart-item-attrs cart-item-group fs-sm">
    @if (showDeliveryTime)
    {
        if (delivery.StatusLabel.HasValue())
        {
            <span>@T("Products.DeliveryTime")</span>
            <span class="delivery-time pl-0" attr-style='(delivery.DisplayDeliveryTimeAccordingToStock, "color:" + delivery.DeliveryTimeHexValue)'>
                <i class="fa fa-circle delivery-time-status"></i>
                <span sm-language-attributes-for="delivery.StatusLabel">@delivery.StatusLabel</span>
            </span>
        }
        if (delivery.DeliveryTimeDate.HasValue())
        {
            <span>@Html.Raw(delivery.StatusLabel.IsEmpty() ? T("Products.DeliveryDate").Value : "&nbsp;")</span>
            <span class="delivery-date">@Html.Raw(delivery.DeliveryTimeDate)</span>
        }
    }

    @if (Model.ShowSku)
    {
        <span>@T("ShoppingCart.SKU"):</span>
        <span>@Model.Sku</span>
    }

    @if (Model.ShowWeight)
    {
        <span>@T("ShoppingCart.Weight"):</span>
        <span>@((Model.Weight * Model.EnteredQuantity).ToString("N2")) @parentModel.MeasureUnitName</span>
    }

    @Html.Raw(Model.EssentialSpecAttributesInfo)

    @if (showVariants)
    {
        @* Spacer *@
        if (showInfos || showEssentialAttributes)
        {
            <span class="pb-1"></span>
            <span></span>
        }

        @Html.Raw(Model.AttributeInfo)
    }
</div>

<div sm-if="Model.RecurringInfo.HasValue()" class="cart-item-recurring-info cart-item-group">
    @Html.Raw(Model.RecurringInfo)
</div>
